package com.jiumi.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jiumi.common.annotation.Log;
import com.jiumi.common.core.controller.BaseController;
import com.jiumi.common.core.domain.AjaxResult;
import com.jiumi.common.enums.BusinessType;
import com.jiumi.order.domain.BaseOrderDetail;
import com.jiumi.order.service.IBaseOrderDetailService;
import com.jiumi.common.utils.poi.ExcelUtil;
import com.jiumi.common.core.page.TableDataInfo;

/**
 * 订单详情Controller
 *
 * @author jiumi
 * @date 2023-05-24
 */
@RestController
@RequestMapping("/order/BaseOrderDetail")
public class BaseOrderDetailController extends BaseController
{
    @Autowired
    private IBaseOrderDetailService baseOrderDetailService;

    /**
     * 查询订单详情列表
     */
    @PreAuthorize("@ss.hasPermi('order:BaseOrderDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseOrderDetail baseOrderDetail)
    {
        startPage();
        List<BaseOrderDetail> list = baseOrderDetailService.selectBaseOrderDetailList(baseOrderDetail);
        return getDataTable(list);
    }

    @GetMapping("/getorderDetailListByOid/{id}")
    public AjaxResult getorderDetailListByOid(@PathVariable("id") Long id)
    {
        List<BaseOrderDetail> list = baseOrderDetailService.selectOrderDetailListByOid(id);
        return AjaxResult.success(list);
    }

    /**
     * 导出订单详情列表
     */
    @PreAuthorize("@ss.hasPermi('order:BaseOrderDetail:export')")
    @Log(title = "订单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseOrderDetail baseOrderDetail)
    {
        List<BaseOrderDetail> list = baseOrderDetailService.selectBaseOrderDetailList(baseOrderDetail);
        ExcelUtil<BaseOrderDetail> util = new ExcelUtil<BaseOrderDetail>(BaseOrderDetail.class);
        util.exportExcel(response, list, "订单详情数据");
    }

    /**
     * 获取订单详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:BaseOrderDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseOrderDetailService.selectBaseOrderDetailById(id));
    }

    /**
     * 新增订单详情
     */
    @PreAuthorize("@ss.hasPermi('order:BaseOrderDetail:add')")
    @Log(title = "订单详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseOrderDetail baseOrderDetail)
    {
        return toAjax(baseOrderDetailService.insertBaseOrderDetail(baseOrderDetail));
    }

    /**
     * 修改订单详情
     */
    @PreAuthorize("@ss.hasPermi('order:BaseOrderDetail:edit')")
    @Log(title = "订单详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseOrderDetail baseOrderDetail)
    {
        return toAjax(baseOrderDetailService.updateBaseOrderDetail(baseOrderDetail));
    }

    /**
     * 删除订单详情
     */
    @PreAuthorize("@ss.hasPermi('order:BaseOrderDetail:remove')")
    @Log(title = "订单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseOrderDetailService.deleteBaseOrderDetailByIds(ids));
    }
}
